#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int weight[18] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
	char check[11] = { 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 };
	int n;
	scanf("%d", &n);
	string *str = new string[n];
	for (int i = 0; i < n; i++)
		cin >> str[i];
	int passCount = 0;
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		bool flag = true;
		for (int j = 0; j < 17; j++)
		{
			if (str[i][j] <= '9' && str[i][j] >= '0')
				sum = sum + int(str[i][j]- '0') * weight[j];
			
			else
			{
				flag = false;
				break;
			}
//			cout << "sum: " << sum << endl;
		}
//		cout << int(str[i][17] - '0') << "  " << (int)check[sum % 11] << endl;
		if (int(str[i][17] - '0') != int(check[sum % 11])) 
			flag = false;
		if (str[i][17] == 'X' && check[sum % 11] == 'X')
			flag = true;
		if (!flag)
			cout << str[i] << endl;
		else
			passCount++;
	}
	if (passCount == n)
		printf("All passed");
	system("PAUSE");
	return 0;
}